import { HttpException, HttpStatus } from '@nestjs/common';
import { ErrorCode, ErrorMessage } from '../constants/error-code.enum';

/**
 * 业务异常类
 * 用于抛出业务逻辑相关的异常
 */
export class BusinessException extends HttpException {
  private errorCode: ErrorCode;

  constructor(errorCode: ErrorCode, message?: string) {
    super(
      {
        code: errorCode,
        message: message || ErrorMessage[errorCode],
      },
      HttpStatus.OK, // 业务异常统一返回 200，通过 code 区分
    );

    this.errorCode = errorCode;
  }

  getErrorCode(): ErrorCode {
    return this.errorCode;
  }
}



